<?php

namespace app\index\controller;

class Index extends \think\Controller
{

    /**
     * 主页
     * @return type
     */
    public function index()
    {
        return $this->fetch();
    }

    /**
     * 登陆
     */
    public function login()
    {
        if (request()->ispost()) {
            //登陆
            $data     = $_POST;
            $username = $data['username'];
            $password = $data['password'];

            $re = \app\index\service\User::login($username, $password, []);
            if (is_string($re)) {
                return $this->error($re);
            } else {
                $url = url('user/index');
                return $this->success('登陆成功', $url);
            }
        } else {
            //展示
            return $this->fetch();
        }
    }

}
